﻿Imports Microsoft.Reporting.WinForms


Public Class ReportViewerForm

    Dim FolderPath As String
    Dim PDFNow As Boolean = False
    Public TheReportToRun As String = ""


    Private Sub ReportViewerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        Dim instance As LocalReport = Me.ReportViewer.LocalReport

        ' AddHandler ReportViewer.LocalReport.SubreportProcessing, _
        '            AddressOf Me.SubreportProcessingEvent

        Me.ReportViewer.RefreshReport()
        ' Me.ReportViewer.RefreshReport()

        '  Me.ReportViewer1.RefreshReport()
        Me.ReportViewer.RefreshReport()
    End Sub

    Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
        Me.Hide()
    End Sub

    Public Sub SubreportProcessingEvent(ByVal sender As Object, _
                                        ByVal e As SubreportProcessingEventArgs)
        Dim DataSetName As String

        DataSetName = "TheStore"
        e.DataSources.Clear()
        e.DataSources.Add(New ReportDataSource(DataSetName, SubreportDataView(e.ReportPath)))

        '      MessageBox.Show(e.ReportPath, "", MessageBoxButtons.OK, MessageBoxIcon.Information)


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PDFButton.Click
        LittleMenu.Show(PDFButton, New System.Drawing.Point(0, PDFButton.Height))
    End Sub

    Private Function ProviderSubCode(ByVal UPIN As Integer) As String

        Dim TheView As DataView

        TheView = LoadDataView("select provider_subtype_code from providers where upin = " & UPIN)

        If TheView.Count = 0 Then
            Return ""
        Else
            Return TheView(0).Item("provider_subtype_code")
        End If


    End Function

    Private Sub PDFCurrentview()
        'PDF Current view
        Dim FileName As String = ""

        Dim extensions As RenderingExtension() = ReportViewer.LocalReport.ListRenderingExtensions()

        For Each extension As RenderingExtension In extensions
            If extension.Name = "PDF" Then

                ''THE NAME
                Dim TheDate As DateTime = Now()
                Dim SQL As String


                If TheReportToRun = "ShadowAllocationsISP" Or TheReportToRun = "ShadowAllocationsAcadSpecial" Or TheReportToRun = "ShadowAllocationsSSF" Then
                    SQL = "Select * from all_provider_Fields where UPIN = '" & SelectBox.SelectedValue & "' and lead = 1"
                Else
                    SQL = "Select * from all_provider_Fields where RID = '" & SelectBox.SelectedValue & "'"
                End If


                Dim InfoView As DataView

                InfoView = LoadDataView(SQL)

                Dim r As DataRowView

                r = InfoView(0)
                Dim TheName As String = Me.Text
                If r("Provider_Type_Code").ToString <> "Local" Then
                    'its a provider

                    Dim ptypecode As String
                    Dim TerCode As String
                    Dim ptypedesc As String
                    Dim DateStr As String

                    Try
                        Select Case r("Provider_Type_Code")
                            Case "Schoo"
                                ptypecode = "18"
                                ptypedesc = "s6f-" & r("LA_Code")
                            Case "Acade"
                                ptypecode = "18"
                                ptypedesc = "aca"
                            Case "Local"
                                ptypecode = "18"
                                ptypedesc = "lau"
                            Case Else
                                Select Case ProviderSubCode(r("UPIN"))
                                    Case "07HEP"
                                        ptypecode = "18"
                                        ptypedesc = "heo"
                                    Case Else
                                        ptypecode = "18"
                                        ptypedesc = "feo"
                                End Select
                        End Select


                    Catch ex As Exception
                        'forget about it!
                        ptypecode = "00"
                        ptypedesc = "__"
                    End Try

                    DateStr = Format(TheDate, "ddMMMyy")

                    Try
                        TerCode = Mid(r("Territory_Name"), 1, 2).ToString.ToLower
                    Catch ex As Exception
                        TerCode = "__"
                    End Try



                    TheName = TheName.Replace(" ", "")
                    TheName = TheName.Replace("(", "")
                    TheName = TheName.Replace("'", "")
                    TheName = TheName.Replace("-", "")
                    TheName = TheName.Replace("&", "and")
                    TheName = TheName.Replace(",", "")
                    TheName = TheName.Replace("/", "")
                    TheName = TheName.Replace("\", "")
                    TheName = TheName.Replace(")", "")

                    TheName = Trim(TheName)

                    Dim Period = Mid(ReportsForm.PeriodBox.SelectedValue.ToString, 1, 6)

                    'FileName = "ypla-" & ptypecode & "12-" & TerCode & "-" & r("UPIN") & "-" & ptypedesc & "-" & Mid(r("Provider_Name"), 1, 10) & "_" & Period & "_" & Mid(TheName, 1, 10) & "-" & DateStr & "-v1"

                    FileName = r("UPIN") & " " & ptypedesc & "-" & Mid(r("Provider_Name"), 1, 10) & "_" & Period & "_" & Mid(TheName, 1, 10) & "-" & DateStr & "-v1"

                    'FileName = TheView(r).Item("UPIN") & " - " & TheView(CurrentRecord).Item("Provider_Name")
                Else
                    'its a LA
                    Dim FileNameBuilder As String = ""
                    Dim TerCode As String = ""

                    Try
                        TerCode = Mid(r("Territory_Name"), 1, 2).ToString.ToLower
                    Catch ex As Exception
                        TerCode = "__"
                    End Try


                    Dim DateStr As String

                    TheName = TheName.Replace(" ", "")
                    TheName = TheName.Replace("(", "")
                    TheName = TheName.Replace("'", "")
                    TheName = TheName.Replace("-", "")
                    TheName = TheName.Replace("&", "and")
                    TheName = TheName.Replace(",", "")
                    TheName = TheName.Replace("/", "")
                    TheName = TheName.Replace("\", "")
                    TheName = TheName.Replace(")", "")

                    DateStr = Format(TheDate, "ddMMMyy")

                    TheName = Trim(TheName)

                    'FileNameBuilder = "ypla-1512-" & TerCode & "-" & LAUPIN(r("LA_Code")) & "-lau" & "-" & r("LA_Code") & "-" & Mid(r("LA_Name"), 1, 20) & Mid(TheName, 1, 8) & "-" & DateStr & "-v1"

                    FileNameBuilder = LAUPIN(r("LA_Code")) & " lau" & "-" & r("LA_Code") & "-" & Mid(r("LA_Name"), 1, 20) & Mid(TheName, 1, 8) & "-" & DateStr & "-v1"

                    FileName = FileNameBuilder
                End If



                FileName = FileName.Replace("&", "and")
                FileName = FileName.Replace(".", "")


                ''THE NAME END

                ''fix this 


                'UPIN
                TheName = RID_To_UPIN(SelectBox.SelectedValue)

                Select Case TheReportToRun
                    Case "rpt_Acad_GAG_Annex_A_DRAFT_FINAL"
                        TheName = TheName & "-" & RID_To_UAI(SelectBox.SelectedValue)
                        TheName = TheName & "-DRG"
                        TheName = TheName & Mid(ReportsForm.PeriodBox.SelectedValue, 3, 4) & "-"

                        TheName = TheName & SelectBox.Text

                        TheName = TheName.Replace("'", "")
                        TheName = TheName.Replace("&", "and")
                        TheName = TheName.Replace(",", "")
                        TheName = TheName.Replace("/", "")
                        TheName = TheName.Replace("\", "")

                        FileName = TheName

                    Case "rpt_Acad_GAG_Annex_C_DRAFT_FINAL"
                        TheName = TheName & "-" & RID_To_UAI(SelectBox.SelectedValue)
                        TheName = TheName & "-(DB)DRG"
                        TheName = TheName & Mid(ReportsForm.PeriodBox.SelectedValue, 3, 4) & "-"

                        TheName = TheName & SelectBox.Text

                        TheName = TheName.Replace("'", "")
                        TheName = TheName.Replace("&", "and")
                        TheName = TheName.Replace(",", "")
                        TheName = TheName.Replace("/", "")
                        TheName = TheName.Replace("\", "")

                        FileName = TheName
                    Case "rpt_Acad_GAG_Annex_A_FINAL_FINAL"
                        TheName = TheName & "-" & RID_To_UAI(SelectBox.SelectedValue)
                        TheName = TheName & "-FRG"
                        TheName = TheName & Mid(ReportsForm.PeriodBox.SelectedValue, 3, 4) & "-"

                        TheName = TheName & SelectBox.Text

                        TheName = TheName.Replace("'", "")
                        TheName = TheName.Replace("&", "and")
                        TheName = TheName.Replace(",", "")
                        TheName = TheName.Replace("/", "")
                        TheName = TheName.Replace("\", "")

                        FileName = TheName
                    Case "rpt_Acad_GAG_Annex_C_FINAL_FINAL"
                        TheName = TheName & "-" & RID_To_UAI(SelectBox.SelectedValue)
                        TheName = TheName & "-(DB)FRG"
                        TheName = TheName & Mid(ReportsForm.PeriodBox.SelectedValue, 3, 4) & "-"

                        TheName = TheName & SelectBox.Text

                        TheName = TheName.Replace("'", "")
                        TheName = TheName.Replace("&", "and")
                        TheName = TheName.Replace(",", "")
                        TheName = TheName.Replace("/", "")
                        TheName = TheName.Replace("\", "")

                        FileName = TheName
                   
                    Case Else

                End Select

              
              
                ReportViewer.ExportDialog(extension, "", FolderPath & "\" & FileName & ".pdf")

            End If
        Next
    End Sub

    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click

        If FolderBrowser.ShowDialog() = Windows.Forms.DialogResult.OK Then
            FolderPath = FolderBrowser.SelectedPath
            PDFCurrentview()
            MessageBox.Show("PDF has been created", "PDF created", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

    End Sub

    Private Sub Load_Acad_GAG_Annex_A()
        Dim TheStoreSQL As String
        Dim EAGDescSQL As String

        If SelectBox.Items.Count = 0 Then Exit Sub

        If SelectBox.SelectedValue.ToString = "System.Data.DataRowView" Then Exit Sub

        TheStoreSQL = "Select * From VW_Acad_Annex_A_Main where RID = '" & SelectBox.SelectedValue & "' and Period_ID = " & ReportsForm.PeriodBox.SelectedValue

        EAGDescSQL = "SELECT * From Acad_EAG_Data where RID = '" & SelectBox.SelectedValue & "' and Period_ID = " & ReportsForm.PeriodBox.SelectedValue


        ShowReport(ReportsForm.ReportLabel.Text, TheReportToRun & ".rdl", "TheStore", TheStoreSQL, "EAG_Descriptions", EAGDescSQL, "", "", "Period", Period_Name(ReportsForm.PeriodBox.SelectedValue), "Report_Header", "", "", "", "", "", "", "", "", "", "", "", "", _
                        "", "", "", "", "", False, False)

    End Sub

    Private Sub Load_Acad_GAG_Annex_C()
        Dim TheStoreSQL As String
        Dim FSQL, GiSQL, GiiSQL As String

        If SelectBox.Items.Count = 0 Then Exit Sub

        If SelectBox.SelectedValue.ToString = "System.Data.DataRowView" Then Exit Sub

        TheStoreSQL = "Select * From VW_Acad_Annex_C_Main where RID = '" & SelectBox.SelectedValue & "' and Period_ID = " & ReportsForm.PeriodBox.SelectedValue

        FSQL = "SELECT     Acad_GAG_Data.RID, Acad_GAG_Data.Period_ID, Acad_GAG_Data.Value, Periods.Period_Name " & _
                "FROM         Acad_GAG_Data INNER JOIN " & _
                "                      Periods ON Acad_GAG_Data.Period_ID = Periods.Period_ID " & _
                "WHERE     (Acad_GAG_Data.Status = 'Approved') AND (Acad_GAG_Data.Dataset_Code = 130) AND (Acad_GAG_Data.Field_Code = 100) " & _
                " and RID = '" & SelectBox.SelectedValue & "' and Acad_GAG_Data.Period_ID = " & ReportsForm.PeriodBox.SelectedValue

        GiSQL = "SELECT     Acad_GAG_Data.Period_ID, Acad_GAG_Data.RID, Acad_GAG_Data.Value, Periods.Period_Name " & _
                "FROM         Acad_GAG_Data INNER JOIN  " & _
                "                      Periods ON Acad_GAG_Data.Period_ID = Periods.Period_ID " & _
                "WHERE     (Acad_GAG_Data.Status = 'Approved') AND (Acad_GAG_Data.Dataset_Code = 140) AND (Acad_GAG_Data.Field_Code = 105) " & _
                " and RID = '" & SelectBox.SelectedValue & "' and Acad_GAG_Data.Period_ID = " & ReportsForm.PeriodBox.SelectedValue

        GiiSQL = "SELECT     Acad_GAG_Data.Period_ID, Acad_GAG_Data.RID, Acad_GAG_Data.Value, Periods.Period_Name " & _
                    "FROM         Acad_GAG_Data INNER JOIN " & _
                    "                      Periods ON Acad_GAG_Data.Period_ID = Periods.Period_ID " & _
                    "WHERE     (Acad_GAG_Data.Status = 'Approved') AND (Acad_GAG_Data.Dataset_Code = 140) AND (Acad_GAG_Data.Field_Code = 100) " & _
                    " and RID = '" & SelectBox.SelectedValue & "' and Acad_GAG_Data.Period_ID = " & ReportsForm.PeriodBox.SelectedValue


        ShowReport(ReportsForm.ReportLabel.Text, TheReportToRun & ".rdl", "TheStore", TheStoreSQL, "F_Startup_Grant_A", FSQL, "Gi_Startup_Grant_B_Form", GiSQL, "Period", Period_Name(ReportsForm.PeriodBox.SelectedValue), "Report_Header", "", "", "", "", "", "", "", "", "", "", "", "", _
                        "", "", "", "", "", False, False, "G_Startup_Grant_B_Assess", GiiSQL)

    End Sub

    Private Sub Load_Acad_GAG_Schedule()
        Dim TheStoreSQL As String

        If SelectBox.Items.Count = 0 Then Exit Sub

        If SelectBox.SelectedValue.ToString = "System.Data.DataRowView" Then Exit Sub

        TheStoreSQL = "select l.Allocation_Description, s.* from " & _
                    "VW_Acad_Allocation_Lines l, " & _
                    "dbo.VW_Acad_Schedule s " & _
                    "where l.Allocation_ID = s.Allocation_ID " & _
                    " and RID = '" & SelectBox.SelectedValue & "' and Period_ID = " & ReportsForm.PeriodBox.SelectedValue

        ShowReport(ReportsForm.ReportLabel.Text, "rpt_Acad_GAG_SCHEDULE.rdl", "TheStore", TheStoreSQL, "", "", "", "", "Period", Period_Name(ReportsForm.PeriodBox.SelectedValue), "Report_Header", "", "", "", "", "", "", "", "", "", "", "", "", _
                        "", "", "", "", "", False, False)

    End Sub

    Private Sub LoadLASummaryReport()
        Dim TheStoreSQL As String
        Dim SENTPGSQL As String
        Dim LearnersSQL As String

        If SelectBox.SelectedValue.ToString = "System.Data.DataRowView" Then Exit Sub

        TheStoreSQL = "select * from dbo.S6F_Summary1112 " & _
                           "where LA_Code = '" & SelectBox.SelectedValue & "'"

        SENTPGSQL = "SELECT     t.LA_Code, coalesce(t.SEN,0) as SEN, coalesce(t.TPG,0) as TPG, coalesce(s.Total_FY,0) as Total_FY " & _
"FROM         (SELECT     LA_Code, MIN(SEN) AS SEN, MIN(TPG) AS TPG " & _
"                       FROM          SEN_TPG_Funding " & _
"                       WHERE      (Period_ID = 2011121) and LA_Code = '" & SelectBox.SelectedValue & "'" & _
"                       GROUP BY LA_Code) AS t LEFT OUTER JOIN " & _
"                          (SELECT     LA_Code, SUM(Total_Funding_4Month + Total_Funding_8Month) AS Total_FY " & _
"                            FROM          S6F_Summary1112 where LA_Code = '" & SelectBox.SelectedValue & "'" & _
"                            GROUP BY LA_Code) AS s ON s.LA_Code = t.LA_Code "

        LearnersSQL = "SELECT     p.UPIN, p.Provider_Name, SUM(a.Learner_Numbers) AS Learner_Numbers " & _
"FROM         Allocations AS a INNER JOIN " & _
"                      All_Provider_Fields AS p ON a.RID = p.RID " & _
"WHERE     (a.Status = 'Approved') AND (a.Allocation_ID NOT IN ('YPB03', 'YPB04', 'YPG01')) AND Period_ID = 2011121 " & _
"and p.LA_Code = '" & SelectBox.SelectedValue & "' " & _
"GROUP BY p.UPIN, p.Provider_Name"

        ShowReport(ReportsForm.ReportLabel.Text, "LA_Summary1112.rdl", "TheStore", TheStoreSQL, "SENTPG", SENTPGSQL, "Learners", LearnersSQL, "Local_Authority", LA_Name(SelectBox.SelectedValue), "Region", LA_RegionName(SelectBox.SelectedValue), "", "", "", "", "", "", "", "", "", "", "", _
                        "", "", "", "", "", False, False)
    End Sub

    Private Sub LoadLASummaryReport1213()
        Dim TheStoreSQL As String
       
        If SelectBox.SelectedValue.ToString = "System.Data.DataRowView" Then Exit Sub

        TheStoreSQL = "select * from VW_LA_Summary " & _
                           "where LA_Code = '" & SelectBox.SelectedValue & "'"

        ShowReport(ReportsForm.ReportLabel.Text, "LA_Summary1213.rdl", "TheStore", TheStoreSQL, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", _
                        "", "", "", "", "", False, False)
    End Sub


    Private Sub SelectBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectBox.SelectedIndexChanged
        RunReport()

    End Sub

    Public Sub RunReport()

        Select Case TheReportToRun
            Case "LA_Summary1112"
                LoadLASummaryReport()
            Case "LA_Summary1213"
                LoadLASummaryReport1213()
            Case "rpt_Acad_GAG_Annex_A_DRAFT_FINAL"
                Load_Acad_GAG_Annex_A()
            Case "rpt_Acad_GAG_Annex_C_DRAFT_FINAL"
                Load_Acad_GAG_Annex_C()
            Case "rpt_Acad_GAG_Annex_A_FINAL_FINAL"
                Load_Acad_GAG_Annex_A()
            Case "rpt_Acad_GAG_Annex_C_FINAL_FINAL"
                Load_Acad_GAG_Annex_C()
            Case "rpt_Acad_GAG_SCHEDULE"
                Load_Acad_GAG_Schedule()
            Case "rpt_Acad_Converters_GAG_Annex_A"
                Load_Acad_Converters_GAG_Annex_A()
            Case "CCM_Funding_Agreement"
                CCMPaymentReport()
            Case "ShadowAllocationsISP"
                ShadowAllocationsISP()
            Case "ShadowAllocationsAcadSpecial"
                ShadowAllocationsAcadSpecial()
            Case "ShadowAllocationsSSF"
                ShadowAllocationsSSF()
            Case Else
                Exit Sub
        End Select

    End Sub

    Private Sub ShadowAllocationsISP()

        PDFButton.Visible = True
        SelectBox.Visible = True

        Dim sql = "SELECT  * FROM   RD_19111211294711 where UPIN = " & SelectBox.SelectedValue

        ShowReport("Shadow Allocations", "Shadow Statement for High Needs - 16-19.rdl", "DataSet1", sql, "", "", "", "", "upin", SelectBox.SelectedValue.ToString, "", "", "", "", "", "", "", "", "", "", _
                  "", "", "", "", "", "", "", "", False, False)

    End Sub

    Private Sub ShadowAllocationsAcadSpecial()

        PDFButton.Visible = True
        SelectBox.Visible = True

        Dim sql = "SELECT  * FROM   RD_22111204255164  where UPIN = " & SelectBox.SelectedValue

        ShowReport("Shadow Allocations", "Shadow Statement for High Needs - Academy Special.rdl", "DataSet1", sql, "", "", "", "", "upin", SelectBox.SelectedValue.ToString, "", "", "", "", "", "", "", "", "", "", _
                  "", "", "", "", "", "", "", "", False, False)

    End Sub

    Private Sub ShadowAllocationsSSF()

        PDFButton.Visible = True
        SelectBox.Visible = True

        Dim sql = "SELECT  * FROM   RD_22111204251310   where UPIN = " & SelectBox.SelectedValue

        ShowReport("Shadow Allocations", "Shadow Statement for High Needs - SSF.rdl", "DataSet1", sql, "", "", "", "", "upin", SelectBox.SelectedValue.ToString, "", "", "", "", "", "", "", "", "", "", _
                  "", "", "", "", "", "", "", "", False, False)
    End Sub

    Private Sub CCMPaymentReport()

        Dim TheView As DataView
        Dim ReportType As String
        Dim RID As String
        Dim SQL As String
        Dim ProviderText As String
        Dim PeriodText As String

        If SelectBox.Items.Count = 0 Then Exit Sub

        If SelectBox.SelectedValue.ToString = "System.Data.DataRowView" Then Exit Sub

        RID = SelectBox.SelectedValue

        'figure out if this is a LA or not
        TheView = LoadDataView("Select Provider_Type_Code, RID from all_provider_fields where RID = '" & RID & "'")
        If TheView(0).Item("Provider_Type_Code").ToString = "Local" Then
            ReportType = "LA"
        Else
            ReportType = "Provider"
        End If


        SQL = "exec spCCM_Funding_Report " & Reportsform.PeriodBox.SelectedValue & ", '" & RID & "'"

        ProviderText = RID_To_UPIN(RID) & " - " & DirectCast(SelectBox.SelectedItem, DataRowView).Item("Provider_Name")

        PeriodText = DirectCast(ReportsForm.PeriodBox.SelectedItem, DataRowView).Item("Period_Name")

        ShowReport("CCM Payment Schedule", "CCM_Funding_Agreement.rdl", "TheStore", Sql, "", "", "", "", "ReportType", ReportType, "ProviderHeader", ProviderText, "Period", PeriodText, "", "", "", "", "", "", _
                   "", "", "", "", "", "", "", "", False, False)


      

    End Sub

    Private Sub Load_Acad_Converters_GAG_Annex_A()
        Dim TheStoreSQL As String
        If SelectBox.Items.Count = 0 Then Exit Sub

        If SelectBox.SelectedValue.ToString = "System.Data.DataRowView" Then Exit Sub

        TheStoreSQL = "Select * From  VW_Acad_Convert_Annex_A where RID = '" & SelectBox.SelectedValue & "' and Period_ID = " & ReportsForm.PeriodBox.SelectedValue

        ShowReport(ReportsForm.ReportLabel.Text, "rpt_Acad_Converters_GAG_Annex_A.rdl", "TheStore", TheStoreSQL, "", "", "", "", "Period", Period_Name(ReportsForm.PeriodBox.SelectedValue), "Report_Header", "", "", "", "", "", "", "", "", "", "", "", "", _
                        "", "", "", "", "", False, False)
    End Sub

    Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
        'PDF Batch

        If SelectBox.Items.Count = 0 Then Exit Sub

        If FolderBrowser.ShowDialog() = Windows.Forms.DialogResult.OK Then
            PDFNow = True
            FolderPath = FolderBrowser.SelectedPath

            If SelectBox.SelectedIndex = 0 Then
                PDFCurrentview()

                If SelectBox.SelectedIndex < SelectBox.Items.Count - 1 Then
                    PDFNow = True
                    SelectBox.SelectedIndex = SelectBox.SelectedIndex + 1
                Else
                    PDFNow = False
                End If

            Else
                PDFNow = True
                SelectBox.SelectedIndex = 0
            End If

        End If



    End Sub

    Private Sub ReportViewer_StatusChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportViewer.StatusChanged

    End Sub

    Private Sub ReportViewer_RenderingComplete(ByVal sender As System.Object, ByVal e As Microsoft.Reporting.WinForms.RenderingCompleteEventArgs) Handles ReportViewer.RenderingComplete
        If PDFNow Then
            If ReportViewer.CurrentStatus.CanExport Then

                PDFCurrentview()

                If SelectBox.SelectedIndex < SelectBox.Items.Count - 1 Then
                    SelectBox.SelectedIndex = SelectBox.SelectedIndex + 1
                Else
                    PDFNow = False
                    MessageBox.Show("PDFs have been created", "PDF created", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            End If
        End If
    End Sub
End Class